package com.ui;


import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Scale;

/**
* @ClassName: SettingsWindow
* @Description: TODO
* @author alterhu2020@gmail.com
* @date Feb 15, 2014 9:25:50 PM
* 
*/

public class SettingsWindow extends Dialog {

	protected Object result;
	protected Shell shlsettingsproperties;
	private Text text_serverip;
	private Text text_serverport;
	


	/**
	 * Create the dialog.
	 * @param parent
	 * @param style
	 */
	public SettingsWindow(Shell parent) {
		super(parent, SWT.DIALOG_TRIM |SWT.CENTER| SWT.APPLICATION_MODAL);
	}

	/**
	 * Open the dialog.
	 * @return the result
	 */
	public Object open() {
		createContents();
		shlsettingsproperties.open();
		shlsettingsproperties.layout();
		Display display = getParent().getDisplay();
		while (!shlsettingsproperties.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		return result;
	}

	/**
	 * Create contents of the dialog.
	 */
	private void createContents() {
		shlsettingsproperties = new Shell(getParent(), getStyle());
		shlsettingsproperties.setImage(SWTResourceManager.getImage(SettingsWindow.class, "/com/images/settings.ico"));
		shlsettingsproperties.setSize(750, 516);
		shlsettingsproperties.setText("系统设置(备注：此处功能已经移植到settings.properties文件中进行配置）");
		shlsettingsproperties.setLayout(new FillLayout(SWT.VERTICAL));
		
		Group group_proxy = new Group(shlsettingsproperties, SWT.NONE);
		group_proxy.setText("\u4EE3\u7406\u8BBE\u7F6E");
		
		Label lblip_proxyserver = new Label(group_proxy, SWT.NONE);
		lblip_proxyserver.setBounds(29, 38, 119, 15);
		lblip_proxyserver.setText("\u4EE3\u7406\u670D\u52A1\u5668IP\u5730\u5740\uFF1A");
		
		text_serverip = new Text(group_proxy, SWT.BORDER);
		text_serverip.setBounds(183, 38, 248, 21);
		
		Label label_serverport = new Label(group_proxy, SWT.NONE);
		label_serverport.setBounds(29, 74, 119, 15);
		label_serverport.setText("\u4EE3\u7406\u670D\u52A1\u5668\u7AEF\u53E3\uFF1A");
		
		text_serverport = new Text(group_proxy, SWT.BORDER);
		text_serverport.setBounds(182, 74, 249, 21);
		
		Button button_proxy_save = new Button(group_proxy, SWT.NONE);
		button_proxy_save.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				String ip=text_serverip.getText().trim();
				int port =Integer.valueOf(text_serverport.getText().trim());
				System.out.println("ip is:"+ip+",port is:"+port);
				//HttpHost proxy = new HttpHost(ip, port, "http");
				//
				//.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
				
			}
		});
		button_proxy_save.setBounds(356, 122, 75, 25);
		button_proxy_save.setText("\u4FDD\u5B58\u8BBE\u7F6E");
		
		Label label_default = new Label(group_proxy, SWT.NONE);
		label_default.setBounds(457, 38, 165, 15);
		label_default.setText("\uFF08\u9ED8\u8BA4\u4E0D\u4F7F\u7528\u4EFB\u4F55\u4EE3\u7406\u4E0A\u7F51\uFF09");
		group_proxy.setTabList(new Control[]{text_serverip, text_serverport, button_proxy_save});
		
		Group grpHttp_http = new Group(shlsettingsproperties, SWT.NONE);
		grpHttp_http.setText("Http\u8BF7\u6C42\u8BBE\u7F6E");
		
		Label lblHttp_requesttime = new Label(grpHttp_http, SWT.NONE);
		lblHttp_requesttime.setBounds(23, 118, 129, 15);
		lblHttp_requesttime.setText("HTTP\u8BF7\u6C42\u8D85\u65F6\u65F6\u95F4\uFF1A");
		
		Scale scale_interval = new Scale(grpHttp_http, SWT.NONE);
		scale_interval.setIncrement(3);
		scale_interval.setMaximum(300);
		scale_interval.setMinimum(30);
		scale_interval.setSelection(1);
		scale_interval.setBounds(158, 103, 170, 42);
		
		Label label_numbercount = new Label(grpHttp_http, SWT.NONE);
		label_numbercount.setBounds(344, 118, 55, 15);
		label_numbercount.setText("0");
		
		Label lblhttp_note = new Label(grpHttp_http, SWT.NONE);
		lblhttp_note.setBounds(23, 26, 583, 45);
		lblhttp_note.setText("\u5907\u6CE8\uFF1A\u5728\u8BF7\u6C42HTTP\u7684\u65F6\u5019\uFF0C\u7CFB\u7EDF\u4F1A\u9ED8\u8BA410\u79D2\u5F97\u5230\u670D\u52A1\u5668\u7684\u54CD\u5E94\u6570\u636E\uFF0C\u5982\u679C\u8D85\u65F6\r\n\u5C06\u4F1A\u505C\u6B62\u8BF7\u6C42\u3002\u4E00\u822C\u5728\u7F51\u7EDC\u6761\u4EF6\u4E0D\u597D\u7684\u60C5\u51B5\u4E0B\u4F1A\u53D1\u751F\u8FD9\u79CD\u60C5\u51B5\u3002\u5982\u679C\u8BBE\u7F6E\u4E86\u6539\u53C2\r\n\u6570\u8BF7\u6C42\u7B49\u5F85\u65F6\u95F4\u4F1A\u52A0\u957F\uFF0C\u8FD9\u6837\u7F51\u7EDC\u518D\u5DEE\u7684\u8BDD\uFF0C\u670D\u52A1\u5668\u7684\u8BF7\u6C42\u4E5F\u662F\u6CA1\u6709\u95EE\u9898\u3002");

	}
}
